<?php
    
    class LoginDAL{
        public function login($uid){
            $result=false;
            $query="select password,level from tb_account where uid=:uid and status=1;";
            $pdo=myPDO::getInstance();
            $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
            $statement->bindValue(":uid",$uid);
            if($statement->execute()){
                $result=$statement->fetch(PDO::FETCH_ASSOC);
            }
            $statement->closeCursor();

            return $result;
        }
    }
    //已废弃
    class MyLogin{
        public static function login($uid,$password,$code){
            $message=array();
            $query = "select password,level,status from tb_account where uid=:uid";
            $pdo=myPDO::getInstance();
            $statement=$pdo->prepare($query,array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
            $statement->bindParam(":uid",$uid);
            $statement->execute();
            //$s->fetchAll(PDO::FETCH_ASSOC);
            if($row=$statement->fetch(PDO::FETCH_ASSOC)){
                $status=$row['status'];
                $myPassword=$row['password'];
                $myPssword=md5($myPassword.$code);

                if($myPssword==$password && $status==1){
                    $_SESSION['uid']=$uid;
                    $_SESSION['level']=$row['level'];
                    $message=array(
                        'code'=>"1001",
                        'message'=>"登录成功",
                        'url'=>"./index.php"
                    );
                }else{
                    $message=array(
                        'code'=>"1004",
                        'message'=>"登录失败，用户名或密码错",
                        'url'=>'./php/tool/verification.php'
                    );
                }
            }else{
                $message=array(
                    'code'=>"1004",
                    'message'=>"登录失败，用户名或密码错误",
                    'url'=>'./php/tool/verification.php'
                );
            }
        
            $statement->closeCursor();
            //$pdo=null;
            return $message;
        }
    }
?>